package com.flashflexpro.flexdirector.model{
    import com.flashflexpro.as3lib.EventDictionary;

    import flash.display.BitmapData;
    import flash.geom.Rectangle;
    import flash.utils.ByteArray;

    import mx.collections.ArrayCollection;
    import mx.utils.ObjectUtil;

    /**
     *
     */
    [Bindable]
    [RemoteClass]
    public class DtoFlexComInst extends DtoReusable{

        public function DtoFlexComInst(){
            name = "Unnamed component inst";
        }

        public var orgAId:String;

        //not null
        public var className:String;

        //not null
        public var automationName:String;
        //not null
        public var automationIndex:String;

        //nullable
        public var automationClassName:String = "";

        //nullable
        public var instId:String = "";

        public var otherData:EventDictionary;

        public var app:DtoApp;

        public var parent:DtoFlexComInst;

        public var children:ArrayCollection;

        public var superClassNames:Array;

        /*

         override public function treeWalk( nodeFunc:Function, self:Object = null, parent:NameAndComment = null ):void{
         super.treeWalk( nodeFunc, self, parent );

         for( var i:int = children.length - 1; i >= 0; i-- ){
         var child:DtoFlexComInst = children.getItemAt( i ) as DtoFlexComInst;
         child.treeWalk( nodeFunc, self, this );
         }
         }
         */


        override public function equals( another:DtoReusable ):Boolean{
            var anotherInst:DtoFlexComInst = another as DtoFlexComInst;
            if( anotherInst == null ){
                return false;
            }
            if( automationClassName == anotherInst.automationClassName &&
                    automationIndex == anotherInst.automationIndex && automationName == anotherInst.automationName &&
                    instId == anotherInst.instId && className == anotherInst.className ){
                return true;
            }
            return false;
        }

        private var _originalAutoId:String;
        /*
         public function getOriginalAutoId():String{
         if( _originalAutoId == null ){
         var stack:Array = [];
         var c:DtoFlexComInst = this;
         while( c != null ){
         stack.push( c );
         c = c.parent;
         }
         var strs:Array = [];
         while( stack.length > 0 ){
         strs.push( getAuoInstId( stack.pop() ) );
         }
         _originalAutoId = strs.join( "|" );
         }
         return _originalAutoId;
         }

         private static function getAuoInstId( inst:DtoFlexComInst ):String{
         var rt:String = null;
         rt = "automationName{" + inst.automationName + "}"

         + "automationIndex{" + inst.automationIndex + "}"

         + "className{" + inst.className + "}";
         if( inst.automationClassName != null && inst.automationClassName.length > 0 ){
         rt += "automationClassName{" + inst.automationClassName + "}";
         }
         if( inst.instId != null && inst.instId.length > 0 ){
         rt += "id{" + inst.instId + "}";
         }

         for( var otherDataName:String in inst.otherData ){
         rt += otherDataName + "{" + inst.otherData[ otherDataName ] + "}";
         }

         return rt;
         }*/
    }
}